#include<bits/stdc++.h>
using namespace std;
const int N=500050;
int T;
int n,m,l,mv;
int d[111111],v[111111],a[111111];
int cs[111111];
bool cmp(pair<int,int> x,pair<int,int> y){
    return x.second<y.second;
}
vector<pair<int,int> > ve;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n>>m>>l>>mv;
        int need=0;
        ve.clear();
        int ans=0;
        for(int i=0;i<n;i++)
        {
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=0;i<m;i++){
            cin>>cs[i];
        }
        for(int i=0;i<n;i++){
            if(a[i]==0){
                if(v[i]<=mv) continue;
                if(d[i]>cs[m-1]) continue;
                int start=lower_bound(cs,cs+m,d[i])-cs;
                ans++;
                ve.push_back(make_pair(start,m-1));
            }
            if(a[i]>0){
                double after=0.00;
                after=(double)(mv*mv-v[i]*v[i])/2.00/(double)(a[i]*1.00)+d[i];
                if(v[i]>mv) after=d[i]-0.01;
                if(after>=cs[m-1]) continue;
                int st=floor(after);
                st+=1;
                int start=lower_bound(cs,cs+m,st)-cs;
                if(start<=m-1){
                    ve.push_back(make_pair(start,m-1));
                    ans++;
                }
            }
            if(a[i]<0)
            {
                if(v[i]<=mv) continue;
                double after=0.00;
                after=(double)(mv*mv-v[i]*v[i])/2.00/(double)(a[i]*1.00)+d[i]-0.0001;
                int en=ceil(after);
                en-=1;
                if(en<cs[0] || d[i]>cs[m-1]) continue;
                int start=lower_bound(cs,cs+m,d[i])-cs;
                int close=upper_bound(cs,cs+m,en)-cs-1;
                if(start<=close){
                    ans++;
                    ve.push_back(make_pair(start,close));
                }
            }
        }
        sort(ve.begin(),ve.end(),cmp);
        int al=-1;
        for(pair<int,int> pa:ve)
        {
            if(pa.first<=al) continue;
            else{
                need++;
                al=pa.second;
            }
        }
        cout<<ans<<" "<<(m-need)<<endl;
    }
    return 0;
}
